import { Component, createApp } from 'vue';
import Quill from 'quill'
const BlockEmbed = Quill.import("blots/block/embed")

export default function (componet: Component) {
  if (!componet.name) {
    throw new Error("组件必须提供name属性")
  }
  const VueWrapper = class extends BlockEmbed {
    static create(propData: any) {
      let node = super.create()
      createApp(componet, propData).mount(node)
      return node
    }
    static tagName = "div"
    static blotName = componet.name
  }

  let key = `formats/${componet.name}`
  return {
    [key]: VueWrapper
  }
}